#include<bits/stdc++.h>
#include<vector>
#include<string>
#define ll long long
#define ull unsigned long long
using namespace std;
const int N=26;
const ll md=1e9+7;
ll n,cnt[26],nt[N],v[N];
string s;
ll pow(ll x,ll y){
ll res=1;
for(int i=1;i<=y;y++){
res*=x;
}
cout<<res<<endl;
return res;
}
struct aa{
ll id,v;
bool operator<(const aa &x){
return v>x.v;
}
};
void solve(){
//fuck
cin>>n;
for(int i=0;i<26;i++){
cnt[i]=0;
nt[i]=0;
v[i]=-1;
}
for(int i=1;i<=n;i++){
cin>>s;
int len=s.length();
for(int j=0;j<len;j++){
if(j==0)nt[s[j]-'a']=1;
cnt[s[j]-'a']+=pow(10,len-j-1);
}
}
vector<aa>zm;
for(int i=0;i<26;i++){
if(cnt[i]==0)continue;
zm.push_back({i,cnt[i]});
}
sort(zm.begin(),zm.end());
int now=2;
for(int i=0;i<zm.size();i++){
if(nt[zm[i].id]){
v[zm[i].id]=1;
break;
}
}
for(int i=0;i<zm.size();i++){
if(!nt[zm[i].id]){
v[zm[i].id]=0;
break;
}
}
for(int i=0;i<zm.size();i++){
if(v[zm[i].id]==-1){
v[zm[i].id]=now;
now++;
}
}
ll ans=0;
for(int i=0;i<zm.size();i++){
ans+=v[zm[i].id]*zm[i].v;
}
cout<<ans<<endl;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int t=1;
// cin>>t;
while(t--){
solve();
}
}
1144D - Equalize Them All | 298A - Snow Footprints |
1753B - Factorial Divisibility | 804A - Find Amir |
1541C - Great Graphs | 607B - Zuma |
30A - Accounting | 959C - Mahmoud and Ehab and the wrong algorithm |
1215A - Yellow Cards | 237B - Young Table |
1216D - Swords | 271D - Good Substrings |
573A - Bear and Poker | 10A - Power Consumption Calculation |
1244B - Rooms and Staircases | 777A - Shell Game |
1698D - Fixed Point Guessing | 415B - Mashmokh and Tokens |
26D - Tickets | 471B - MUH and Important Things |
982B - Bus of Characters | 1102B - Array K-Coloring |
818A - Diplomas and Certificates | 70A - Cookies |
798A - Mike and palindrome | 1690F - Shifting String |
366B - Dima and To-do List | 120B - Quiz League |
740A - Alyona and copybooks | 1491A - K-th Largest Value |